const path = require('path');
const webpack = require('webpack');

let clientEntry = {
    main: ['./example/index.js'],
};

let browserConfig = {
    // 入口
    entry: clientEntry,
    // target: 'node',
    // 输出
    output: {
        path: path.join(__dirname, '/dist'),
        publicPath: './',
        filename: '[name].client.js',
        chunkFilename: '[id].[chunkhash:8].bundle.js',
    },
    // resolve: {},
    // resolveLoader: {
    //     modules: ['node_modules'],
    //     extensions: ['.js', '.json'],
    //     mainFields: ['loader', 'main']
    // },
    module: {
        rules: [
            {
                test: /\.(css)$/,
                use: [
                    'style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            modules: false,
                            importLoaders: 1,
                            sourceMap: false,
                            minimize: false,
                            autoprefixer: false,
                            localIdentName: '[name]__[local]__[hash:base64:8]',
                        },
                    },
                ],
            },
            {
                test: /\.scss$/,
                use: [
                    'style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            modules: false,
                            importLoaders: 1,
                            sourceMap: false,
                            minimize: false,
                            autoprefixer: false,
                            localIdentName: '[name]__[local]__[hash:base64:8]',
                        },
                    },
                    {
                        loader: 'sass-loader',
                    }
                ],
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: [{
                    loader: 'babel-loader',
                }],
            },
            {
                test: /\.(eot|woff|woff2|svg|ttf)([\?]?.*)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            style: {
                                sass: true,
                                less: true,
                                stylus: true,
                                pcss: true,
                            },
                            template: {
                                jade: true,
                            }
                        },
                    },
                ],
            },
            {
                test: /\.(png|jpe?g|gif)/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 2048,
                            name: '[name].[ext]',
                        },
                    },
                ],
            },
            {
                test: /\.wtemplate$/,
                use: [
                    {
                        loader: 'wsearch-style-loader',
                    },
                    {
                        loader: 'wsearch-loader',
                    },
                ],
                //  include: [path.resolve(__dirname, 'node_modules/wsearch-loader')]
            },
        ]
    },
    resolveLoader: {
        alias: {
            'wsearch-loader': require.resolve('./lib'),
            'wsearch-style-loader': require.resolve('./stylelib')
        }
    },
    plugins: [
        // new webpack.LoaderOptionsPlugin({
        //     debug: true
        // })
    ],
    devtool: 'source-map',
};

module.exports = [browserConfig];
